
Rem
	Return information about words used in a string.
	
	str_word_count2 was added to deal with string array output
	
	@author	Nicholas Grant
	@updatedby	
	@return	int
	@return	string array
EndRem
Function str_word_count:Int(str:String)
	
	If (str.Length > 0)
		
		Local splitLetters:String[] = str_split(str)
		Local currentLetterValue:Int = 0
		Local splitLettersLength:Int = splitLetters.Length
		Local newWord:String = ""
		Local splitWordsList:TList = New TList
		For Local cnt:Int = 0 To splitLettersLength - 1
			currentLetterValue = Asc(splitLetters[cnt])
			If ((currentLetterValue > 64 And currentLetterValue < 91) Or (currentLetterValue > 96 And currentLetterValue < 123))
				newWord:+splitLetters[cnt]
			Else
				If (newWord <> "") Then splitWordsList.AddLast(newWord)
				newWord = ""
			End If
		Next
		Return splitWordsList.Count();
		
	End If
	
	Return 0;
	
End Function

Function str_word_count2:String[] (str:String, format:Int = 1, charlist:String = "")
	Local splitWords:String[]
	If (str.Length > 0)
		Local splitLetters:String[] = str_split(str)
		Local newWord:String = ""
		Local currentLetterValue:Int = 0
		Local splitLettersLength:Int = splitLetters.Length - 1
		Local skipToNext:Int = False
		Local splitWordsList:TList = New TList
		Select (format)
			Case 1
				For Local cnt:Int = 0 To splitLettersLength
					currentLetterValue = Asc(splitLetters[cnt])
					If ((currentLetterValue > 64 And currentLetterValue < 91) Or ..
						(currentLetterValue > 96 And currentLetterValue < 123))
						newWord:+splitLetters[cnt]
					Else
						If (newWord <> "") Then splitWordsList.AddLast(newWord)
						newWord = ""
					EndIf
				Next
			Case 2
				Local charlistValue:Int[] = New Int[charlist.Length]
				For Local cnt:Int = 0 To charlist.Length - 1
					charlistValue[cnt] = Asc(substr(charlist, cnt, 1))
				Next
				For Local cnt:Int = 0 To splitLettersLength
					currentLetterValue = Asc(splitLetters[cnt])
					If ((currentLetterValue > 64 And currentLetterValue < 91) Or ..
						(currentLetterValue > 96 And currentLetterValue < 123))
						newWord:+splitLetters[cnt]
					Else
						For Local cnt2:Int = 0 To charlistValue.Length - 1
							If (currentLetterValue = charlistValue[cnt2] And Not skipToNext)
								newWord:+splitLetters[cnt]
								skipToNext = True
							EndIf
						Next
						If (Not skipToNext)
							If (newWord <> "") Then splitWordsList.AddLast(newWord)
							newWord = ""
						EndIf
					EndIf
					skipToNext = False
				Next
		EndSelect
		If (newWord <> "") Then splitWordsList.AddLast(newWord)
		splitWords = New String[splitWordsList.count()]
		For Local cnt:Int = 0 To splitWordsList.count() - 1
			splitWords[cnt] = splitWordsList.ValueAtIndex(cnt).ToString()
		Next
		Return splitWords
	EndIf
	splitWords = [""]
	Return splitWords
EndFunction
